package org.coderead.model;

import org.coderead.calculator.AbstractPerformanceCalculator;

import java.util.List;
import java.util.Map;

/**
 * 发票
 *
 * @author kendoziyu
 * @since 2020/10/11 0011
 */
public class Invoice {

    private String customer;

    private List<Performance> performances;

    public String getCustomer() {
        return customer;
    }

    public void setCustomer(String customer) {
        this.customer = customer;
    }

    public List<Performance> getPerformances() {
        return performances;
    }

    public void setPerformances(List<Performance> performances) {
        this.performances = performances;
    }

    public int getTotalAmount(Map<String, Play> plays) {
        return getPerformances().stream().mapToInt(performance -> getPerformanceCalculator(plays.get(performance.getPlayId()).getType())
                .getAmount(performance)).sum();
    }

    public int getVolumeCredits(Map<String, Play> plays) {
        return getPerformances().stream().map(performance -> getPerformanceCalculator(plays.get(performance.getPlayId()).getType())
                        .getVolumeCredit(performance))
                .mapToInt(Double::intValue).sum();
    }

    private AbstractPerformanceCalculator getPerformanceCalculator(String playType) {
        return AbstractPerformanceCalculator.of(playType);
    }
}
